package com.lxz.aiagentbackend.rag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;

/**
 * 初始化向量数据库
 */
@Configuration
@Slf4j
public class FitnessCoachAppVectorStoreConfig {
    @Resource
    private FitnessCoachAppDocumentLoader fitnessCoachAppDocumentLoader;

    @Bean
    VectorStore fitnessCoachAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel)
                .build();
        // 加载文档
        List<Document> documents = fitnessCoachAppDocumentLoader.loadDocuments();
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }
}
